import { defineStore } from "pinia";
import { ref } from "vue"
import { get_discuss_back, Deleteoone } from "@/apis/DiscussApi"
import { ElMessage } from "element-plus";
const DiscussStore = defineStore('discuss', () => {
    //前台-------------------------------------------------------------------
    //  即将回复的评论的id和昵称
    let will_reply = ref({
        username: "",
        parent_comment_id: ''
    })
    const send_replay = (username: string, parent_comment_id: string) => {
        will_reply.value.username = username
        will_reply.value.parent_comment_id = parent_comment_id
        console.log(will_reply.value)
    }
    //前台--------------------------------------------------------------------
    //后台------------------------------------------------------------------
    const get_list = async (skp: number, types: string) => {
        const result = await get_discuss_back(skp, types)
        // console.log(result)
        return result
    }
    //删除一个
    const delete_one = async (id: string) => {
        const result: any = await Deleteoone(id)
        console.log(result)
        if (result.code === 200) {
            ElMessage({
                type: "success",
                message: "删除成功"
            })
        } else {
            ElMessage({
                type: "error",
                message: "删除失败"
            })
        }
    }
    //后台------------------------------------------------------------------
    return {
        will_reply,
        send_replay,
        get_list,
        delete_one
    }
})

export default DiscussStore